#ifndef _HTTPHEADERSTREAM_HPP_
#define _HTTPHEADERSTREAM_HPP_

#include "jhdefs.hpp"
#include "net/HTTPSession.hpp"
#include "HTTPBasicStreamBuf.hpp"
#include "net/MemoryPool.hpp"

#include <istream>
#include <ostream>

NET_NAMESPACE_BEGIN


//
// CHTTPHeaderStreamBuf
//
class CHTTPHeaderStreamBuf : public HTTPBasicStreamBuf
{
public:
	typedef HTTPBasicStreamBuf::openmode openmode;

	CHTTPHeaderStreamBuf(CHTTPSession& session, openmode mode);
	~CHTTPHeaderStreamBuf();

protected:
	int readFromDevice(char* buffer, std::streamsize length);
	int writeToDevice(const char* buffer, std::streamsize length);

private:
	CHTTPSession& m_session;
	bool         m_end;
};


//
// CHTTPHeaderIOS
//
class CHTTPHeaderIOS : public virtual std::ios
{
public:
	CHTTPHeaderIOS(CHTTPSession& session, CHTTPHeaderStreamBuf::openmode mode);
	~CHTTPHeaderIOS();
	CHTTPHeaderStreamBuf* rdbuf();

protected:
	CHTTPHeaderStreamBuf m_buf;
};


//
// CHTTPHeaderInputStream
//
class CHTTPHeaderInputStream : public CHTTPHeaderIOS, public std::istream
{
public:
	CHTTPHeaderInputStream(CHTTPSession& session);
	~CHTTPHeaderInputStream();

	void* operator new(std::size_t size);
	void operator delete(void* ptr);

private:
	static CMemoryPool m_pool;
};


//
// CHTTPHeaderOutputStream
//
class CHTTPHeaderOutputStream : public CHTTPHeaderIOS, public std::ostream
{
public:
	CHTTPHeaderOutputStream(CHTTPSession& session);
	~CHTTPHeaderOutputStream();

	void* operator new(std::size_t size);
	void operator delete(void* ptr);

private:
	static CMemoryPool m_pool;
};

NET_NAMESPACE_END

#endif
